﻿package plugin.findFriend.game
{
    import com.core.*;
    import com.sh.game.consts.*;
    import com.sh.game.global.*;
    import com.sh.game.net.*;
    import flash.events.*;
    import flash.filters.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.findFriend.*;
    import plugin.social.consts.*;
    import uiresource.friend.*;

    public class SearchGame extends SearchUI
    {
        private var _selected:Box;
        private var _instance:FindFriend;

        public function SearchGame(param1:FindFriend)
        {
            this._instance = param1;
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            var _loc_1:* = Control.create(FindFriendControl, this);
            ModelProxy.addObserver("social", _loc_1);
            return;
        }// end function

        public function initEvent() : void
        {
            btn_close1.clickHandler = new Handler(this.doClose);
            txt_searchMsg.addEventListener(MouseEvent.MOUSE_DOWN, this.doStop);
            txt_searchMsg.addEventListener(FocusEvent.FOCUS_IN, this.doFocusIn);
            txt_searchMsg.addEventListener(FocusEvent.FOCUS_OUT, this.doFocusOut);
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.focusNone);
            btn_find.addEventListener(MouseEvent.CLICK, this.doFind);
            list_msg.mouseHandler = new Handler(this.msgHandler);
            btn_add.clickHandler = new Handler(this.addHandler);
            btn_see.clickHandler = new Handler(this.seeHandler);
            return;
        }// end function

        protected function focusNone(event:MouseEvent) : void
        {
            GlobalLayer.instance.root.focus = null;
            return;
        }// end function

        protected function doFocusOut(event:FocusEvent) : void
        {
            if (txt_searchMsg.text == "")
            {
                txt_searchMsg.text = "此处支持模糊搜索";
            }
            return;
        }// end function

        protected function doFocusIn(event:FocusEvent) : void
        {
            if (txt_searchMsg.text == "此处支持模糊搜索")
            {
                txt_searchMsg.text = "";
            }
            return;
        }// end function

        private function seeHandler() : void
        {
            if (this._selected && this._selected.hasOwnProperty("dataSource"))
            {
                Server.instance.send(114, 7, this._selected.dataSource.rid, 0, ConnectType.SYSTEM);
            }
            else
            {
                ModelProxy.change("movetips", "error", "请选择要查看的玩家");
            }
            return;
        }// end function

        private function addHandler() : void
        {
            if (this._selected && this._selected.hasOwnProperty("dataSource"))
            {
                PluginManager.instance.sendToServer("social", CMDSocial.APPLYFOR, this._selected.dataSource.rid);
            }
            else
            {
                ModelProxy.change("movetips", "error", "请选择要添加的玩家");
            }
            return;
        }// end function

        private function msgHandler(event:MouseEvent, param2:int) : void
        {
            var _loc_3:* = list_msg.getCell(param2);
            switch(event.type)
            {
                case MouseEvent.ROLL_OVER:
                {
                    if (this._selected == _loc_3)
                    {
                        return;
                    }
                    _loc_3.filters = [new GlowFilter(16777215, 0.5, 6, 6, 2, 1, true)];
                    break;
                }
                case MouseEvent.ROLL_OUT:
                {
                    if (this._selected == _loc_3)
                    {
                        return;
                    }
                    _loc_3.filters = null;
                    break;
                }
                case MouseEvent.CLICK:
                {
                    if (this._selected)
                    {
                        this._selected.filters = null;
                    }
                    _loc_3.filters = [new GlowFilter(16750597, 0.5, 6, 6, 2, 1, true)];
                    this._selected = _loc_3;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function doFind(event:MouseEvent) : void
        {
            var _loc_2:* = txt_searchMsg.text;
            if (_loc_2 == "" || _loc_2 == "此处支持模糊搜索" || _loc_2 == "输入玩家姓名")
            {
                ModelProxy.change("movetips", "error", "请输入搜索信息！");
            }
            else
            {
                PluginManager.instance.sendToServer("social", CMDSocial.searchRole, _loc_2);
            }
            return;
        }// end function

        protected function doStop(event:MouseEvent) : void
        {
            event.stopPropagation();
            return;
        }// end function

        private function doClose() : void
        {
            this.visible = false;
            this.removeEvent();
            return;
        }// end function

        public function removeEvent() : void
        {
            btn_close1.clickHandler = null;
            txt_searchMsg.removeEventListener(MouseEvent.MOUSE_DOWN, this.doStop);
            txt_searchMsg.removeEventListener(FocusEvent.FOCUS_IN, this.doFocusIn);
            txt_searchMsg.removeEventListener(FocusEvent.FOCUS_OUT, this.doFocusOut);
            txt_searchMsg.removeEventListener(MouseEvent.MOUSE_DOWN, this.doStop);
            return;
        }// end function

        public function updateMsg(param1:Object) : void
        {
            if (this._selected)
            {
                this._selected.filters = null;
            }
            this._selected = null;
            var _loc_2:* = param1 as Array;
            if (_loc_2.length > 0)
            {
                txt_select.visible = false;
                list_msg.visible = true;
            }
            else
            {
                txt_select.visible = true;
                txt_select.text = "很抱歉，你查找的玩家不在线或用户不存在!";
                list_msg.visible = false;
            }
            list_msg.array = _loc_2;
            list_msg.renderHandler = new Handler(this.msgRender);
            return;
        }// end function

        private function msgRender(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Label = null;
            var _loc_5:Label = null;
            var _loc_6:String = null;
            var _loc_7:Label = null;
            if (param2 < list_msg.length)
            {
                _loc_3 = list_msg.array[param2];
                _loc_4 = param1.getChildByName("txt_name1") as Label;
                _loc_4.text = _loc_3.name;
                _loc_5 = param1.getChildByName("txt_zhiye") as Label;
                _loc_6 = "";
                if (_loc_3.career == "1")
                {
                    _loc_6 = "战士";
                }
                else if (_loc_3.career == "2")
                {
                    _loc_6 = "法师";
                }
                else
                {
                    _loc_6 = "道士";
                }
                _loc_5.text = _loc_6;
                _loc_7 = param1.getChildByName("txt_level1") as Label;
                _loc_7.text = _loc_3.rein + "转" + _loc_3.level + "级";
            }
            return;
        }// end function

    }
}
